<template>
  <div class="coin-container">
    <TitleBar title="金币与聚合金币值查询" refresh />
    <div class="select-con">
      <div class="scon">
        <div class="dhead clearfix">筛选查询</div>
        <div class="dbd">
          <div class="dbd-lef">
            <div>
              <label for>用户账号：</label>
              <!-- <input type="text" placeholder="用户ID/账号" /> -->
              <el-input
                v-model="ID"
                placeholder="用户ID"
                clearable
                style="width: 8vw"
                @change="searchBtn"
              />
            </div>
            <div>
              <label for>用户昵称：</label>
              <el-input
                v-model="username"
                placeholder="用户昵称"
                clearable
                style="width:8vw"
                @change="searchBtn"
              />
            </div>
            <div>
              <label for>用户等级：</label>
              <el-select v-model="levelvalue" @change="changevalue" placeholder="请选择">
                <el-option
                  v-for="item in leveloptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <!-- <input type="text" placeholder="用户等级" /> -->
              <!-- <input type="text" placeholder="用户ID/账号"> -->
            </div>
            <p>
              <!-- <label for>用户昵称：</label>
              <input type="text" placeholder="用户昵称">-->
            </p>
            <p>
              <!-- <label for>用户等级：</label>
              <input type="text" placeholder="用户等级">-->
            </p>
          </div>
          <div class="dbd-rig">
            <a href="javascript:;" @click="search()">搜索</a>
          </div>
        </div>
      </div>
    </div>
    <div class="data-list clearfix">
      <div class="dhead clearfix">
        <p>数据列表</p>
        <ul class="dh-rig clearfix">
          <li class="abg">
            <!-- <el-select v-model="showVal" filterable placeholder="显示条数">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>-->
          </li>
          <li class="abg">
            <!-- <el-select v-model="sort" placeholder=" 排序方式">
              <el-option
                v-for="item in sortoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>-->
          </li>
        </ul>
      </div>
      <div class="data-bd">
        <el-table
          ref="multipleTable"
          :data="queryData"
          align="center"
          style="width: 100%;margin-left:-1px"
          class="table-class"
          :header-cell-style="{
            'background-color': '#fafafa',
            'color':'#333',
            'height':'56px',
            'line-height':'56px',
            'font-size':'14px',
            'background': 'rgba(242, 242, 242, 1)'
          }"
        >
          <el-table-column type="selection" width="100" align="center"></el-table-column>
          <el-table-column prop="userCode" label="用户ID" width="300" align="center"></el-table-column>
          <el-table-column prop="userCount" label="用户账号" align="center"></el-table-column>
          <el-table-column prop="userName" label="用户昵称" show-overflow-tooltip align="center"></el-table-column>
          <el-table-column prop="levName" label="会员等级" show-overflow-tooltip align="center"></el-table-column>
          <el-table-column prop="goldCoin" label="可用金币" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column prop="historyGoldCoin" label="历史金币" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column
            prop="polymerizationCoin"
            label="聚合金币数 "
            width="200"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column prop="action" label="操作" show-overflow-tooltip align="left" width="150">
            <template slot-scope="scope">
              <div class="action" style="width:86px;color:#488DFF;text-align:left">
                <p>
                  <el-button type="text" @click="goCoin(scope.row)">金币明细</el-button>
                </p>
                <p>
                  <el-button type="text" @click="goMerge(scope.row)">聚合金币明细</el-button>
                </p>
                <p style="color:#FF2C2C">
                  <el-button
                    type="text"
                    style="color:#FF2C2C"
                    @click="editcoinDialog=true,editcoin(scope.row)"
                  >修改数值</el-button>
                </p>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 修改金币dialog -->
      <div class="dialog">
        <el-dialog title="提示" :visible.sync="editcoinDialog" width="844px" center>
          <div slot="title" class="header-title">
            <div class="lef">
              <i />
              <span class="title-name">修改用户金币信息</span>
            </div>
          </div>
          <div class="dialog-bd">
            <el-form
              ref="ruleForm"
              :model="ruleForm"
              :rules="rules"
              label-width="100px"
              class="demo-ruleForm"
            >
              <div class="top coinbox clearfix">
                <p class="fl">修改金币：</p>
                <div class="frig fr">
                  <el-radio-group v-model="radio" @change="coinChange">
                    <div class="rline">
                      <el-radio label="1">增加</el-radio>
                      <div class="rinput">
                        <el-form-item prop="addname">
                          <el-input
                          :disabled="radio==1?false:true"
                          :v-model="radio==1?ruleForm.addname:ruleForm.addname=''"
                            v-model="ruleForm.addname"
                            @input="proving"
                            placeholder="请输入大于0"
                          />
                        </el-form-item>
                      </div>
                      <span>次</span>
                    </div>
                    <div class="rline">
                      <el-radio label="0">减少</el-radio>
                      <div class="rinput">
                        <el-form-item prop="downname">
                          <el-input
                          :disabled="radio==1?true:false"
                          :v-model="radio==0?ruleForm.downname:ruleForm.downname=''"
                            v-model="ruleForm.downname"
                            placeholder="请输入大于0"
                            @input="downValue"
                          />
                        </el-form-item>
                      </div>
                      <span>次</span>
                    </div>
                  </el-radio-group>
                </div>
              </div>
              <div class="foot coinbox">
                <p class="fl">修改聚合金币：</p>
                <div class="frig fr">
                  <el-radio-group v-model="radio1" @change="jcoinChange">
                    <div class="rline">
                      <el-radio label="1">增加</el-radio>
                      <div class="rinput">
                        <el-form-item prop="addname1">
                          <el-input
                          :disabled="radio1==1?false:true"
                          :v-model="radio1==1?ruleForm.addname1:ruleForm.addname1=''"
                            v-model="ruleForm.addname1"
                            placeholder="请输入大于0"
                            @input="changeValue"
                          />
                        </el-form-item>
                      </div>
                      <span>次</span>
                    </div>
                    <div class="rline">
                      <el-radio label="0">减少</el-radio>
                      <div class="rinput">
                        <el-form-item prop="downname1">
                          <el-input
                          :disabled="radio1==1?true:false"
                          :v-model="radio1==0?ruleForm.downname1:ruleForm.downname1=''"
                            v-model="ruleForm.downname1"
                            placeholder="请输入大于0"
                            @input="changeValue1"
                          />
                        </el-form-item>
                      </div>
                      <span>次</span>
                    </div>
                  </el-radio-group>
                </div>
              </div>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button
              style="width: 100px;height: 40px;background: rgba(204, 204, 204, 1);border-radius: 2px;"
              @click="editcoinDialog = false,resetForm('ruleForm')"
            >取 消</el-button>
            <el-button
              type="primary"
              style="width: 100px;height: 40px;background:rgba(72,141,255,1);border-radius: 2px;"
              @click="SureBtn('ruleForm')"
            >确 定</el-button>
          </span>
        </el-dialog>
      </div>
      <!-- 分页 -->
      <div class="pagination-block">
        <!-- <el-button type="primary" @click="delAll(multipleSelection)">批量删除</el-button> -->
        <el-pagination
          prev-text="上一页"
          next-text="下一页"
          :background="true"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next,total,slot, jumper"
          :total="this.dataTotal?this.dataTotal:0"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
          <div class="page-number" layout="slot">
            <div class="jump-button">跳至</div>
          </div>
        </el-pagination>
      </div>
      <div class="clear" />
    </div>
  </div>
</template>
<script>
import { getCoin, updateCoin } from "@/api/usermanage.js";
export default {
  inject: ["reload"],
  data() {
    var validnum = (rule, value, callback) => {
      if (Number(value) >= 0) {
        return callback(new Error("数字应大于0"));
      } else {
        callback();
      }
    };
    return {
      a:false,
      currentPage: 1,
      pageNum: 1,
      pageSize: 4,
      dataTotal: "",
      // checked: true,
      ID: "",
      username: "",
      levelCode: "",
      editcoinDialog: false, //修改数值对话框
      radio: "1",
      radio1: "1",
      btnstatus1: false,
      btnstatus: true,
      queryData: [],
      options: [
        {
          value: "选项1",
          label: "3条一页"
        }
      ],
      sortoptions: [
        {
          value: "选项1",
          label: "倒序"
        }
      ],
      leveloptions: [
        {
          value: "0",
          label: "普通"
        },
        {
          value: "1",
          label: "白银"
        },
        {
          value: "2",
          label: "黄金"
        },
        {
          value: "3",
          label: "白金"
        },
        {
          value: "4",
          label: "钻石"
        }
      ],
      levelvalue: "",
      showVal: "",
      sort: "",
      userCode: "", //用户编码
      ruleForm: {
        addname: "",
        downname: "",
        addname1: "",
        downname1: ""
      },
      formtype: {
        coinadd: "",
        coindown: "",
        jcoinadd: "",
        jcoindown: ""
      },
      rules: {
        // addname: [{ validator: validnum, require: false, type:'number',trigger: "change" }],
        // downname: [{ validator: validnum, trigger: "change" }],
        // addname1: [{ validator: validnum, trigger: "change" }],
        // downname1: [{ validator: validnum, trigger: "change" }]
      }
    };
  },
  created() {
    //获取金币信息
    this.getCoinlist();
    this.formtype.coinadd = 1;
    this.formtype.jcoinadd = 1;
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleClick(row) {
      console.log(row);
      this.addlevelDialog = true;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(currentPage) {
      this.pageNum = currentPage;
      this.getCoinlist();
      console.log(`当前页: ${currentPage}`);
    },
    // 刷新
    refbtn() {
      this.reload();
    },
    getCoinlist() {
      getCoin({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        userCode: this.ID,
        userName: this.username,
        levelCode: this.levelCode
      }).then(res => {
        console.log(res);
        this.queryData = res.data.list;
        this.dataTotal = res.data.total;
      });
    },
    searchBtn() {
      if (this.ID === "" || this.username === "" || this.showVal) {
        this.getCoinlist();
      }
    },
    //搜索
    search() {
      this.getCoinlist();
    },
    changevalue(value) {
      // console.log(value)
      this.levelCode = value;
      console.log(this.levelCode);
      // alert(e);
    },
    //聚合详情
    goMerge(row) {
      this.$router.push({
        name: "polymerge-detail",
        query: {
          userCode: row.userCode
        }
      });
    },
    //金币详情
    goCoin(row) {
      console.log(row);
      this.$router.push({
        name: "goldcoin-detail",
        query: {
          userCode: row.userCode
        }
      });
    },
    coinChange(val) {
      // console.log(val);
      let that = this;
      this.formtype.coinadd = val;
      // console.log(this.formtype.coinadd);
      // that.btnstatus = val === "1" ? true : false;
      // that.btnstatus1 = val === "0" ? true : false;
    },
    jcoinChange(val) {
      this.formtype.jcoinadd = val;
      // console.log(this.formtype.jcoinadd);
    },
    proving(val) {
      this.ruleForm.addname = this.ruleForm.addname.replace(/[^\.\d]/g, "");
      // console.log(val, this.ruleForm.addname);
    },
    downValue(val) {
      this.ruleForm.downname = this.ruleForm.downname.replace(/[^\.\d]/g, "");
      // console.log(val, this.ruleForm.downname);
    },
    changeValue(val) {
      this.ruleForm.addname1 = this.ruleForm.addname1.replace(/[^\.\d]/g, "");
      // console.log("zhi:", this.ruleForm.addname1);
    },
    changeValue1(val) {
      this.ruleForm.downname1 = this.ruleForm.downname1.replace(/[^\.\d]/g, "");
      // console.log("zhi:", this.ruleForm.downname1);
    },
    //修改金币数值
    editcoin(row) {
      console.log(row);
      this.userCode = row.userCode;
    },
    // 确认修改
    SureBtn() {
      let { addname, downname, addname1, downname1 } = this.ruleForm;
      let { coinadd, jcoinadd } = this.formtype;
      let dd = [
        {
          coin:
            this.formtype.coinadd == 1
              ? this.ruleForm.addname !== ""
                ? this.ruleForm.addname
                : this.$message({
                    message: "请填写添加数量",
                    type: "warning"
                  })
              : this.ruleForm.downname !== ""
              ? this.ruleForm.downname
              : this.$message({
                  message: "请填写减少数量",
                  type: "warning"
                }),
          userCode: this.userCode,
          operationType: this.formtype.coinadd,
          coinType: "g"
        },
        {
          coin:
            this.formtype.jcoinadd == 1
              ? this.ruleForm.addname1 !== ""
                ? this.ruleForm.addname1
                : this.$message({
                    message: "请填写添加数量",
                    type: "warning"
                  })
              : this.ruleForm.downname1 !== ""
              ? this.ruleForm.downname1
              : this.$message({
                  message: "请填写减少数量",
                  type: "warning"
                }),
          userCode: this.userCode,
          operationType: this.formtype.jcoinadd,
          coinType: "j"
        }
      ];
      if (!addname && !downname && !addname1 && !downname1) {
        this.editcoinDialog = false;
      } else {
        // 可以同时加减
        // if (jcoinadd == 1 && !addname1) {
        //   return;
        // }
        // if (jcoinadd == 0 && !downname1) {
        //   return;
        // }
        // if (coinadd == 1 && !addname) {
        //   return;
        // }
        // if (coinadd == 0 && !downname) {
        //   return;
        // }
        if (coinadd == 0 && jcoinadd == 1 && downname && addname1) {
          this.$message({
            message: "不能同时加减",
            type: "warning"
          });
          return;
        }
        if (coinadd == 1 && jcoinadd == 0 && addname && downname1) {
          this.$message({
            message: "不能同时加减",
            type: "warning"
          });
          return;
        }
        updateCoin(dd).then(res => {
          if (res.code == 200) {
            this.getCoinlist();
            this.$message({
              type: "success",
              message: "更新成功"
            });
            this.ruleForm.addname = "";
            this.ruleForm.downname = "";
            this.ruleForm.addname1 = "";
            this.ruleForm.downname1 = "";
          }
        });
        this.editcoinDialog = false;
        this.ruleForm.addname = "";
        this.ruleForm.downname = "";
        this.ruleForm.addname1 = "";
        this.ruleForm.downname1 = "";
      }
    },
    // 取消重置
    resetForm(editform) {
      this.$refs[editform].resetFields();
    }
  }
};
</script>
<style lang="scss" scoped>
.coin-container {
  width: 100%;
  padding: 0 110px 0 26px;
  margin: 16px 0;
  .dashboard-text {
    margin-top: 17px;
    // width: 1517px;
    height: 37px;
    .lef {
      line-height: 37px;
      font-size: 16px;
      font-weight: 900;
      color: #333;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      i {
        display: inline-block;
        width: 11px;
        height: 20px;
        background: #488dff;
        border-radius: 4px;
        margin-right: 12px;
      }
    }
    .rig {
      font-size: 14px;
      width: 76px;
      height: 37px;
      text-align: center;
      line-height: 37px;
      background: #488dff;
      border-radius: 4px;
      line-height: 37px;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      cursor: pointer;
    }
  }

  .select-con {
    // width: 1517px;
    // height: 150px;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 10px 0px rgba(4, 0, 0, 0.1);
    border-radius: 4px;
    margin-bottom: 30px;
    .scon {
      padding: 25px 0 0 29px;
      .dhead {
        // width: 1463px;
        height: 60px;
        font-size: 16px;
        padding-right: 24px;
        font-family: PingFang-SC-Medium;
        font-weight: 500;
        border-bottom: 1px solid rgba(242, 242, 242, 1);
      }
      .dbd {
        width: 100%;
        display: flex;
        align-items: center;
        padding: 24px 23px 24px 29px;
        .dbd-lef {
          display: flex;
          flex: 5;
          > div {
            margin-right: 30px;
            label {
              color: rgba(51, 51, 51, 1);
            }
          }
          p {
            float: left;
            label {
              color: rgba(51, 51, 51, 1);
            }
          }
          p:nth-child(2) {
            // margin: 0 60px;
            margin-left: 30px;
            margin-right: 30px;
          }
          input[type="text"] {
            // width: 240px;
            height: 40px;
            border: 1px solid rgba(204, 204, 204, 1);
            border-radius: 2px;
            color: #999;
            padding-left: 11px;
          }
        }
        .dbd-rig {
          float: right;
          a {
            display: block;
            width: 100px;
            height: 40px;
            background: rgba(72, 141, 255, 1);
            border-radius: 2px;
            color: #fff;
            text-align: center;
            line-height: 40px;
            margin-left: 80px;
          }
        }
      }
    }
  }
  //data-list
  .data-list {
    // width: 1517px;
    height: auto;
    min-height: 1200px;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 10px 0px rgba(4, 0, 0, 0.1);
    border-radius: 4px;
    padding: 10px 24px 30px 30px;
    .dhead {
      // width: 1463px;
      // height: 60px;
      line-height: 60px;
      font-size: 16px;
      padding-right: 24px;
      font-family: PingFang-SC-Medium;
      font-weight: 500;
      border-bottom: 1px solid rgba(242, 242, 242, 1);
      overflow: hidden;
      margin-bottom: 24px;
      p {
        float: left;
      }
      .dh-rig {
        float: right;
        // overflow: hidden;
        li {
          float: left;
          list-style: none;
          width: 100px;
          height: 40px;
          line-height: 40px;
          color: #fff;
          margin-left: 40px;
          background: rgba(72, 141, 255, 1);
          border-radius: 1px;
          text-align: center;
        }
        .abg {
          width: 124px;
          height: 40px;
          // border: 1px solid rgba(204, 204, 204, 1);
          // border-radius: 1px;
          color: #999;
          background: #fff;
          position: relative;
          // &:after {
          //   content: "";
          //   display: inline-block;
          //   width: 0px;
          //   height: 0px;
          //   border-top: 8px solid #cccccc;
          //   border-left: 8px solid transparent;
          //   border-right: 8px solid transparent;
          //   position: absolute;
          //   top: 16px;
          //   left: 98px;
          // }
        }
      }
    }
    .data-bd {
      height: auto;
      margin-bottom: 40px;
      padding-bottom: 20px;
      .el-checkbox__inner {
        width: 24px !important;
        height: 24px !important;
      }
    }
    .clear {
      clear: both;
      height: 200px;
    }
  }
  // 对话框
  .dialog {
    width: 844px;
    .header-title {
      height: 56px;
      overflow: hidden;
      .lef {
        float: left;
        line-height: 37px;
        font-size: 16px;
        font-weight: 900;
        color: #333;
        i {
          float: left;
          margin-top: 8.5px;
          width: 11px;
          height: 20px;
          background: rgba(72, 141, 255, 1);
          border-radius: 4px;
          margin-right: 12px;
        }
      }
      .rig {
        float: right;
        display: block;
        width: 22px;
        height: 22px;
      }
    }
    //
    .dialog-bd {
      width: 66%;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-direction: column;
      .coinbox {
        // width: 309px;
        p {
          margin-right: 30px;
          height: 30px;
          line-height: 59px;
        }
        .frig {
          .rline {
            display: flex;
            align-items: center;
            // background: #ccc;
            .rinput {
              width: 121px;
              margin-top: 10px;
            }
            .el-form-item {
              margin-bottom: 22px;
              margin-left: -100px;
            }
          }
        }
      }
      .dialog-footer {
        .el-button {
          width: 100px;
          height: 40px;
          background: rgba(204, 204, 204, 1);
          border-radius: 2px;
        }
      }
    }
  }
}
</style>
